const express = require('express')
const multer = require('multer')
const path = require('path')
const router = express.Router()
// const upload = multer({ dest: 'uploads/' })

const storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, 'public/images')
    },
    filename: function (req, file, cb) {
      const uniqueSuffix = Date.now()+Math.round(Math.random() * 1E9)
      cb(null, uniqueSuffix + path.extname(file.originalname))
    }
  })
  
  const upload = multer({ storage: storage })


router.post('/',upload.single('image'),function(req,res){

    let {filename,fieldname} = req.file
    console.log(fieldname+'/'+filename)
    res.send({
        code:'1',
        msg:'上传成功'
    })
})

module.exports = router